package utils

import (
	"fmt"
	"time"
)

func TileTimer() (timeStart string, timeEnd string) {
	//昨日0点格式化时间
	ts := time.Now().AddDate(0, 0, -1)
	timeYesterday := time.Date(ts.Year(), ts.Month(), ts.Day(), 0, 0, 0, 0, ts.Location()).Unix()
	timeStart = time.Unix(timeYesterday, 0).Format("2006-01-02")
	////昨天0点格式化时间
	//timeStampStart := addTime.Unix()
	//fmt.Println(timeStampStart) // 1649952000
	//fmt.Println(timeStart) //2022-11-13
	timeEnd = timeStart
	return
}

func MetricTimer() (timeStart string, timeEnd string) {
	//昨日0点格式化时间
	ts := time.Now().AddDate(0, 0, -1)
	timeYesterday := time.Date(ts.Year(), ts.Month(), ts.Day(), 0, 0, 0, 0, ts.Location()).Unix()
	timeStart = time.Unix(timeYesterday, 0).Format("2006-01-02 15:04:05")
	////昨天0点格式化时间
	//timeStampStart := time.Date(ts.Year(), ts.Month(), ts.Day(), 0, 0, 0, 0, ts.Location()).Unix()
	//fmt.Println(timeStampStart) // 1649952000
	//fmt.Println(timeStart) //2022-11-13

	//当天0点格式化时间
	t := time.Now()
	addTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
	timeEnd = addTime.Format("2006-01-02 15:04:05")
	////当天0点格式化时间
	//timeStampEnd := addTime.Unix()
	//fmt.Println(timeStampEnd) // 1649952000
	//fmt.Println(timeEnd) // 2022-11-14

	return
}

func WeekDate(num int) {
	for num := 0; num < 7; num++ {
		nTime := time.Now()
		yesTime := nTime.AddDate(0, 0, -num)
		fmt.Printf("%v\n", yesTime.Format("20060102"))
		return
	}
}

//获取任意12点时间戳
func RandomTime(num int) int64 {

	nTime := time.Now()

	timeTime := nTime.AddDate(0, 0, num)

	timeStr := timeTime.Format("2006-01-02")

	t, _ := time.ParseInLocation("2006-01-02", timeStr, time.Local)

	return t.UnixNano()
}

//获取昨晚12点时间戳
func YesterdayTime() int64 {

	timeTime := time.Now()

	timeStr := timeTime.Format("2006-01-02")

	t, _ := time.ParseInLocation("2006-01-02", timeStr, time.Local)

	return t.UnixNano()
}

//获取今晚12点时间戳
func TodayTime() int64 {
	nTime := time.Now()

	timeTime := nTime.AddDate(0, 0, 1)

	timeStr := timeTime.Format("2006-01-02")

	t, _ := time.ParseInLocation("2006-01-02", timeStr, time.Local)

	return t.UnixNano()
}

func GetTimeArr(start, end string) int64 {
	timeLayout := "2006-01-02 15:04:05"
	loc, _ := time.LoadLocation("Local")
	// 转成时间戳
	startUnix, _ := time.ParseInLocation(timeLayout, start, loc)
	endUnix, _ := time.ParseInLocation(timeLayout, end, loc)
	startTime := startUnix.Unix()
	endTime := endUnix.Unix()
	// 求相差天数
	x := endTime - startTime
	date := x / 86399
	return date
}
